package com.literaryfamily.literaryfamily.enumPackage;

import com.literaryfamily.literaryfamily.exceptions.OperationException;
import com.literaryfamily.literaryfamily.myUtil.StringUtil;

public enum OperatorType {
	BORROW(0, "借阅单", "bb"),
	SALE(1, "买卖单", "bs"),
	RETURN(2, "退货单", "rb"),
	PAYMENT(3, "支付单", "pa"),
	BORROW_ONLINE(4, "买卖上架单", "bo"),
	SALE_ONLINE(5, "借阅上架单", "so");

	OperatorType(int typeNum, String typeName, String prefix) {
		this.typeNum = typeNum;
		this.typeName = typeName;
		this.prefix = prefix;
	}

	private final int typeNum;
	private final String typeName;
	private final String prefix;

	public int getTypeNum() {
		return typeNum;
	}

	public String getTypeName() {
		return typeName;
	}

	public String getPrefix() {
		return prefix;
	}

	public static OperatorType getStaticByPrefix(String prefix) {
		if (StringUtil.isNull(prefix) || StringUtil.isNull(prefix.trim())) {
			throw new OperationException("没有找到对应操作类型");
		}
		prefix = StringUtil.extractPrefix(prefix, 2);
		for (OperatorType OperatorType : OperatorType.values()) {
			if (OperatorType.getPrefix().equals(prefix)) {
				return OperatorType;
			}
		}
		throw new OperationException("没有找到对应操作类型");
	}
}